package com.LFLWZ.utils;

import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
* 随机数工具类
* @author  kups
* @since 2020-12-2
*/

@Component
public class RandomUtils {

   /**
    * 随机字母+数字
    */
   public static String getRandomArticleId(int num) {
       String val = "";
       java.util.Random random = new java.util.Random();
       for ( int i = 0; i <num; i++ ) {
           String str = random.nextInt( 2 ) % 2 == 0 ? "num" : "char";
           if ( "char".equalsIgnoreCase( str ) )
           { // 产生字母
               System.out.println();
               int nextInt = random.nextInt( 2 ) % 2 == 0 ? 65 : 97;
               // System.out.println(nextInt + "!!!!"); 1,0,1,1,1,0,0
               val += (char) ( nextInt + random.nextInt( 26 ) );
           }
           else if ( "num".equalsIgnoreCase( str ) )
           { // 产生数字
               val += String.valueOf( random.nextInt( 10 ) );
           }
       }
       return val;
   }


   /**
    * 2、验证码随机数---6位数字
    * @return 650032(6位)
    *
    */
   public  static int randomNum() {
       return (int)((Math.random()*9+1)*100000);
   }


   /**
    * 生成图片唯一id 22位
    * 3位随机数 + 14位时间戳 + 5位随机数
    *
    * @return
    */
   public static  String getrandomImageId(){
       int a=(int)((Math.random()*9+1)*100);
       String b= new SimpleDateFormat("yyyMMddhhmmss").format(new Date());
       int c= (int)((Math.random()*9+1)*10000);
       return a+b+c;
   }





}
